SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the MessageConfig table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.MessageConfig_Find
(

	@SearchUsingOR bit   = null ,

	@KeyCode varchar (15)  = null ,

	@Value nvarchar (200)  = null ,

	@TypeId int   = null ,

	@Language varchar (10)  = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null ,

	@CreatedUser varchar (50)  = null ,

	@UpdatedUser varchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [KeyCode]
	, [Value]
	, [TypeId]
	, [Language]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[MessageConfig]
    WHERE 
	 ([KeyCode] = @KeyCode OR @KeyCode IS NULL)
	AND ([Value] = @Value OR @Value IS NULL)
	AND ([TypeId] = @TypeId OR @TypeId IS NULL)
	AND ([Language] = @Language OR @Language IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser IS NULL)
	AND ([UpdatedUser] = @UpdatedUser OR @UpdatedUser IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [KeyCode]
	, [Value]
	, [TypeId]
	, [Language]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[MessageConfig]
    WHERE 
	 ([KeyCode] = @KeyCode AND @KeyCode is not null)
	OR ([Value] = @Value AND @Value is not null)
	OR ([TypeId] = @TypeId AND @TypeId is not null)
	OR ([Language] = @Language AND @Language is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([UpdatedUser] = @UpdatedUser AND @UpdatedUser is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
